package com.yxym.object_;

public class Equals01 {
    public static void main(String[] args) {
        A a = new A();
        A b = a;
        A c = a;
        System.out.println(a==c);//T
        System.out.println(b==c);//T
        int num1 = 20;
        double num2 = 2.0;
        System.out.println(num1==num2);
        //基本数据类型，判断值是否相等


        "hello".equals("abc");
        //1.查看Object类 equals的源码，输入Ctrl + b
        /*
        public boolean equals(Object anObject) {
        if (this == anObject) {//如果是同一个对象
            return true;//返回true
        }
        if (anObject instanceof String) {//判断类型
            String anotherString = (String)anObject;//向下转型
            int n = value.length;
            if (n == anotherString.value.length) {//长度相同
                char v1[] = value;
                char v2[] = anotherString.value;
                int i = 0;
                while (n-- != 0) {//比较字符长度
                    if (v1[i] != v2[i])
                        return false;
                    i++;
                }
                return true;//如果两个字符都相等返回true
            }
        }
        return false;//不是字符串直接返回false
    }
         */

        //2.查看Object下的子类
//        public boolean equals(Object obj) {
//            return (this == obj);
            // 判断两个对象(地址)是否相同(关键！！)
//        }

        /*3.Integer 重写了Object 的equals方法
        //判断两个值是否相等(关键啊！！！)
        (Integer integer = new Integer(5);)

        public boolean equals(Object obj) {
        if (obj instanceof Integer) {
            return value == ((Integer)obj).intValue();
        }
        return false;
    }
         */
    }
}
class A{

}
class B extends A{

}
